/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import type {ReactNode} from 'react';
import React from 'react';
import {View, Text, Image, StyleSheet, ScrollView} from 'react-native';
import {BreakpointsReference, GridCol, GridRow, GridRowDirection} from '@hadss/react_native_adaptive_layout/src';
import AvoidContainer from '../../components/AvoidContainer/AvoidContainer';

/**
 * @description 网格布局
 * @returns ReactNode
 */
const Page = (): ReactNode => {
  // 渲染列表项
  const renderItem = (): ReactNode => {
    const uri = require('../../../assets/grid/background.jpg');
    return (
      <View style={styles.imgContainer} tabIndex={0} focusable={true} accessible={true}>
        <Image source={uri} style={styles.img} resizeMode="cover" />
        <View style={{paddingTop: 5, paddingBottom: 5}}>
          <View style={styles.title}>
            <Text style={styles.titleText}>标题</Text>
          </View>
          <View style={styles.subTitle}>
            <Text style={styles.subTitleText}>副标题</Text>
          </View>
        </View>
      </View>
    );
  };

  const list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];

  return (
    <AvoidContainer>
      <ScrollView showVerticalScrollIndicator={false}>
        <GridRow
          style={styles.gridRow}
          columns={12}
          gutter={8}
          breakpoints={{
            reference: BreakpointsReference.ComponentSize,
          }}
          direction={GridRowDirection.Row}>
          {list.map((item, index) => (
            <GridCol
              offset={0}
              order={0}
              span={{
                xs: 6,
                sm: 6,
                md: 3,
                lg: 3,
                xl: 2,
              }}
              key={index}>
              {renderItem()}
            </GridCol>
          ))}
        </GridRow>
      </ScrollView>
    </AvoidContainer>
  );
};
export default Page;

const styles = StyleSheet.create({
  gridRow: {
    flex: 1,
    backgroundColor: '#fff',
    paddingTop: 6,
    paddingBottom: 6,
  },
  imgContainer: {
    backgroundColor: '#f0f0f0',
    borderRadius: 6,
    padding: 6,
  },
  img: {
    width: '100%',
    height: null,
    aspectRatio: 4 / 5,
    borderRadius: 12,
  },

  title: {
    width: '100%',
    marginBottom: 5,
    justifyContent: 'center',
    alignItems: 'center',
  },
  titleText: {
    color: '#000',
    fontSize: 16,
  },
  subTitle: {
    width: '100%',
    justifyContent: 'center',
    alignItems: 'center',
  },
  subTitleText: {
    color: '#b0b0b0',
    fontSize: 12,
  },
});
